Okay.
So today we are going to have a look at click detectors.
Now click detectors are very commonly used or very commonly used in quite a lot of games.
Whether that's to open up a GUI, um, to perform an operation, like to open a door or to start a car
or something like that, they're quite commonly used, okay.
And they're quite simple as well.
So let's add a part in and see how click detectors might be used.
So we have our parts here.
And a click detector is actually an object that we're going to add in okay.
Let's add in a click detector like that like that there.
And let's just play the game and see how this would happen or how it would work if we played the game.
So we go over to the part and when my mouse goes over it, a little click icon appears that allows me
to click it like that as well.
So it kind of prompts the player to click it with this icon.
Okay, um, you probably would want something here saying click or a little mouse button icon so the
player knows it's supposed to click it.
But um, you don't need to do anything else apart from that.
Okay.
So the click detector itself doesn't have many properties apart from the max activation distance, which
is how many studs away the player can activate it, and also the ability to change the cursor icon.
So the picture that your mouse has when you hover over it.
Okay.
So add a script inside of I'm going to add it inside the script.
Click detector okay.
And click detectors are quite simple.
They just work based on a simple event okay.
So let's reference the click detector I'm going to use a variable for it.
I think it's a bit cleaner to use a variable for it.
Click detector.
Is a good script dot parent okay.
And we're going to say click detector dot I'm going to say mount dot mouse click okay.
And this fires when the player clicks the click detector.
When the prompt is up okay.
Connect that with a function okay.
And we also have a parameter here called player.
And that parameter there will basically store the player who clicked the click detector okay.
So you know you could go ahead and do whatever you'd like to the player or reference their character
or whatever.
Okay.
What we're going to do is when they click detect the clicked detector, we're going to kill them okay.
So I'm going to show you how that works as um, I always think is important as well.
So you know how to do that for a lot of games and involve players dying.
So you need to know how to do that as well.
Okay.
So um, we need to reference the humanoids now referencing the humanoid previously.
Sorry.
We need to reference the character first, then the humanoid referencing the character has been a bit
difficult before because obviously they take longer to load.
However, um, if the player has has been able to spawn into the game, walk over to the click detector
and left click it and their character is definitely in the game.
Okay, so you can assume that the that the character exists because it'd be basically impossible for
them to click the to click detector without the character being loaded in loaded in.
Okay, there might be a split second, but it might be able to, but it's just so unlikely that you
can basically forget about it.
So reference the humanly character the normal way by just saying player dot character.
And then as I said earlier, you need to reference the humanoid as well.
So local humanoid is equal to character.
Um, dot humanoid.
Again, we don't need to say on wait for child humanoid because again, you can be sure that the humanoid
exists just as it is normally.
Okay, so let's play the game.
And um, we're going to have a look at, um, the humanoid and see what property we might be changing.
So I've got my character here.
My humanoid.
I'm a humanoid, has a property here called health.
That's when we're going to be changing.
Okay.
So all you need to say is humanoid dot health is equal to zero because the player, when the player
doesn't have any health, they die.
Okay.
There are a couple other different ways to kill the player.
You can break their joints and do other stuff as well, but I think this is probably the simplest method
to do that.
So let's play the game and see what happens.
So let's walk over to the click detector.
Let's left click it and my player dies there.
Okay.
So as simple as that.
All we need to do to kill a player is just set the health to zero.
Okay.
And that's it for click detectors.
It's a short one.
I wanted to show you how to use them, because it's a new event that you might not have found out or
figured out how to do otherwise.
And click detectors are quite commonly used in a lot of games.
Okay.
Um, if you want it to look really nice and modern, though, I would suggest changing the cursor to
something else as it's repeatedly used in a lot of different games.
But yeah, that's it.
That's it.
Under that they are quite cool.
And join me in the next lesson where we're going to learn about tools and how to script them.